<%--
  Created by IntelliJ IDEA.
  User: 老头
  Date: 2023/4/13
  Time: 12:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@page import="java.sql.*"%>
    <%@page import="util.*"%>
    <title>Title</title>
    <%
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("myName");
        String password = request.getParameter("myPassword");
        String gender = request.getParameter("gender") != null ? "男" : "女";
        String phone = request.getParameter("phone");
        String introduce = request.getParameter("introduce");
        String email = request.getParameter("email");
        System.out.println(gender);
        Connection connection = JDBCUtil.getConnection();
        String sql = "INSERT INTO `user` (username, password,gender,email,telephone,introduce, registTime) VALUES (?,?,?,?,?,?,?)";
//        String sql = "INSERT INTO user (username, userpassword) VALUES (?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, password);
        preparedStatement.setString(3, gender);
        preparedStatement.setString(4, email);
        preparedStatement.setString(5, phone);
        preparedStatement.setString(6, introduce);
        preparedStatement.setDate(7, new Date( new java.util.Date().getTime()));

        int execute = preparedStatement.executeUpdate();

        if(execute >= 1){
            out.println("插入成功！");
            response.sendRedirect("registersuccess.jsp");
        }


//        ResultSet rs = stmt.executeQuery("select * from product");//查询整个用户表数据
//        while(rs.next()){//遍历整个表数据
//            out.print("<BR>");
//            out.print("  id：" + rs.getInt(1));
//            out.print(";  书名：" + rs.getString(2));
//            out.print(";  书名：" + rs.getString(3));
//            out.print("<BR>");
//        }
    %>
</head>
<body>

</body>
</html>
